package leetcode.Leetcode560;

class DraftSolution {
    public int subarraySum(int[] nums, int k) {
        //枚举 O(n3)
        int len = nums.length;
        int ans=0;
        for (int i = 0; i < len; i++) {
            for (int j = i; j < len; j++) {
                int currSum=0;
                for (int l = i; l <= j ; l++) {
                    currSum += nums[l];
                }
                if (currSum==k) {
                    ans++;
                }
            }
        }
        return ans;
    }
    public int subarraySum1(int[] nums, int k) {
        //O(n2)
        int count = 0;
        for (int start = 0; start < nums.length; ++start) {
            int sum = 0;
            for (int end = start; end >= 0; --end) {
                sum += nums[end];
                if (sum == k) {
                    count++;
                }
            }
        }
        return count;
    }

}